package com.example.stmp.Controller;

import com.example.stmp.Entity.TeachClass;
import com.example.stmp.Service.TeachClass.TeachClassService;
import com.example.stmp.pojo.PageResult;
import com.example.stmp.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/TeachClass")
public class TeachClassController {

    @Autowired
    private TeachClassService teachClassService;

    /*
     * 新增教学班
     * */
    @PostMapping
    public Result save(@RequestBody TeachClass teachClass) {

        log.info("新增部门: {}", teachClass);
        teachClassService.save(teachClass);
        return Result.success();
    }

    /*
     *批量删除教学班
     * */
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids) {

        log.info("删除教学班: {}", ids);
        teachClassService.delete(ids);
        return Result.success();
    }

    /*
     * 修改教学班级信息
     * */
    @PutMapping
    public Result update(@RequestBody TeachClass teachClass) {

        log.info("修改部门信息: {}", teachClass);
        teachClassService.update(teachClass);
        return Result.success();

    }

    /*
     * 根据tcId查询教学班级信息
     * */
    @GetMapping("/{id}")
    public Result<TeachClass> getById(@PathVariable Long id) {

        log.info("查询id为{}的部门信息", id);
        TeachClass teachClass = teachClassService.selectTeachClassInfoById(id);
        return Result.success(teachClass);
    }

    /*
     * 教学班级的分页查询
     * */
    @GetMapping("/page")
    public Result<PageResult> Page(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize) {

        // 执行分页查询
        PageResult pageResult = teachClassService.queryPage(pageNum, pageSize);

        return Result.success(pageResult);
    }
}
